package com.ror.java.se.stream;

import java.util.ArrayList;
import java.util.Arrays;

/* 需求：
    创建集合添加学生对象
    学生对象属性：name，age
    要求：
        获取姓名并放到数组当中
        使用方法引用完成
 */

public class Demo06 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student("zhangsan",23));
        list.add(new Student("lisi",24));
        list.add(new Student("wangwu",25));

        String[] names = list.stream().map(Student::getName).toArray(String[]::new);
        System.out.println(Arrays.toString(names));
    }

    static class Student{
        String name;
        int age;

        Student(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public Student() {
        }

        /**
         * 获取
         * @return name
         */
        public String getName() {
            return name;
        }

        /**
         * 设置
         * @param name
         */
        public void setName(String name) {
            this.name = name;
        }

        /**
         * 获取
         * @return age
         */
        public int getAge() {
            return age;
        }

        /**
         * 设置
         * @param age
         */
        public void setAge(int age) {
            this.age = age;
        }

        public String toString() {
            return "Student{name = " + name + ", age = " + age + "}";
        }
    }
}
